package h0724;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
  * @description 输出指定字母在字符串的中的索引
  * @author 不知名帅哥
  * @date 2024/7/24 9:05
  * @version 1.0
*/
public class CharacterIndexInString {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.next();
        int index = sc.nextInt()-1;
//        getResult(s,index);
        String[] split = s.split("");
        String[] array = Arrays.stream(split).sorted(String::compareTo).toArray(String[]::new);
        String aim = array[index];
        for (int i = 0; i < split.length; i++) {
            if (split[i].equals(aim)){
                System.out.println(i);
                break;
            }
        }
    }

    public static void getResult(String s,int index){
        char[] chars = s.toCharArray();
        Arrays.sort(chars);
        char c = chars[index];
        int res = s.indexOf(c);
        System.out.println(res);
    }
}
